package com.black.app.service.impl.store;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.black.app.domain.req.store.query.AppStoreProductSpecificationsQueryReq;
import com.black.app.domain.resp.store.AppStoreProductSpecificationsResp;
import com.black.app.domain.store.AppStoreProductSpecifications;
import com.black.app.service.store.AppStoreProductSpecificationsService;
import com.black.app.mapper.store.AppStoreProductSpecificationsMapper;
import com.black.common.exception.database.PrimaryException;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
* @author 12572
* @description 针对表【app_store_product_specifications】的数据库操作Service实现
* @createDate 2024-10-28 16:39:25
*/
@Service
public class AppStoreProductSpecificationsServiceImpl extends ServiceImpl<AppStoreProductSpecificationsMapper, AppStoreProductSpecifications>
    implements AppStoreProductSpecificationsService{

    @Override
    public AppStoreProductSpecificationsResp findById(Long id) {
        if (Objects.isNull(id)){
            throw new PrimaryException();
        }
        //根据主键查询
        AppStoreProductSpecifications appStoreProductSpecifications = this.getById(id);
        if (Objects.isNull(appStoreProductSpecifications)){
            throw new PrimaryException();
        }
        AppStoreProductSpecificationsResp resp = new AppStoreProductSpecificationsResp();
        BeanUtils.copyProperties(appStoreProductSpecifications,resp);
        return resp;
    }

    @Override
    public PageInfo<AppStoreProductSpecificationsResp> paginationQuery(AppStoreProductSpecificationsQueryReq req) {
        return PageHelper.startPage(req.getPageNum(), req.getPageSize()).doSelectPageInfo(() -> {
            this.baseMapper.paginationQuery(req);
        });
    }

    @Override
    public List<AppStoreProductSpecifications> findByPidAll(Integer productId) {
        LambdaQueryWrapper<AppStoreProductSpecifications> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(AppStoreProductSpecifications::getProductId, productId);
        return this.list(wrapper);
    }

    @Override
    public List<AppStoreProductSpecifications> findByPid(Integer pid) {
        LambdaQueryWrapper<AppStoreProductSpecifications> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(AppStoreProductSpecifications::getProductId, pid);
        return this.list(wrapper);
    }


}




